/*
 * Copyright 2016. chenshufei
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package sz.szsmk.citizencard.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import sz.szsmk.citizencard.R;


/**
 * <br /> author: chenshufei
 * <br /> date: 16/2/19
 * <br /> email: chenshufei2@sina.com
 */
public class GestureDialog extends Dialog implements View.OnClickListener {

    private Button btn_ok;
    private TextView content;
    private TextView title;
    private OnOkClickListener mOnOkClickListener;
    private OnCancelClickListener mOnCancelClickListener;
    private String contentTxt;
    private String titleTxt;
    private Button btn_cancel;

    public interface OnOkClickListener {
        void onOkClick();
    }

    public interface OnCancelClickListener {
        void onCancelClick();
    }

    public GestureDialog(Context context) {
        super(context);
    }

    public GestureDialog(Context context, String title, String content) {
        super(context);
        titleTxt = title;
        contentTxt = content;
    }

    public GestureDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.gesture_dialog);
        btn_ok = (Button) findViewById(R.id.btn_ok);
        btn_cancel = (Button) findViewById(R.id.btn_cancel);
        content = (TextView) findViewById(R.id.tv_success);
        title = (TextView) findViewById(R.id.title);
        if (titleTxt != null) {
            title.setText(titleTxt);
        }
        if (contentTxt != null) {
            content.setText(contentTxt);
        }

        btn_ok.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    public void setOnOkClickListener(OnOkClickListener onOkClickListener) {
        this.mOnOkClickListener = onOkClickListener;
    }

    public void setOnCancelClickListener(OnCancelClickListener onOkClickListener) {
        this.mOnCancelClickListener = onOkClickListener;
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.btn_ok) {
            dismiss();
            if (null != mOnOkClickListener) {
                mOnOkClickListener.onOkClick();
            }
        } else if (id == R.id.btn_cancel) {
            dismiss();
            if (null != mOnCancelClickListener) {
                mOnCancelClickListener.onCancelClick();
            }
        }
    }
}
